﻿<template>
	<div class="card-fill layout-padding" v-loading="loading" element-loading-text="Loading...">
		<el-card shadow="hover" class="layout-padding-auto create-form">
			<el-form ref="formRef" :model="stateData.vmModel" label-width="120px">
				<div class="form-section">
					<div class="section-title">
						<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
						<span>履历信息</span>
					</div>

					<el-row :gutter="20">
						<!-- <el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_ResumeType_FormItem" prop="Entity.ResumeType">
								<template #label>
									<WtmLabelTooltip label="履历类型" tooltip="履历类型，如调岗、晋升等" />
								</template>
								<el-input v-model="stateData.vmModel.Entity.ResumeType" disabled clearable class="width100"></el-input>
							</el-form-item>
						</el-col> -->
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_StartDate_FormItem" prop="Entity.StartDate">
								<template #label>
									<WtmLabelTooltip label="起始日期" tooltip="履历起始日期" />
								</template>
								<el-date-picker v-model="stateData.vmModel.Entity.StartDate" disabled clearable class="width100"></el-date-picker>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_EndDate_FormItem" prop="Entity.EndDate">
								<template #label>
									<WtmLabelTooltip label="结束日期" tooltip="履历结束日期" />
								</template>
								<el-date-picker v-model="stateData.vmModel.Entity.EndDate" disabled clearable class="width100"></el-date-picker>
							</el-form-item>
						</el-col>
					</el-row>
				</div>

				<div class="form-section">
					<div class="section-title">
						<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
						<span>原职位信息</span>
					</div>

					<el-row :gutter="20">
						<el-col :xs="24" :lg="12" class="mb20" v-if="!stateData.vmModel.Entity.OriginalDepartmentPosition">
							<WtmDeptSelector
								v-model:model-value="stateData.vmModel.Entity.OriginalGroupId"
								prop="Entity.OriginalGroupId"
								label="原部门"
								:auth="false"
								:rules="[]"
								:disabled="true"
							/>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20" v-if="!stateData.vmModel.Entity.OriginalDepartmentPosition">
							<el-form-item ref="Entity_OriginalPositionId_FormItem" prop="Entity.OriginalPositionId">
								<template #label>
									<WtmLabelTooltip label="原岗位" tooltip="原岗位" />
								</template>
								<el-select v-model="stateData.vmModel.Entity.OriginalPositionId" disabled clearable class="width100">
									<el-option v-for="item in stateData.AllSysJobPositions" :key="item.Value" :value="item.Value" :label="item.Text"></el-option
								></el-select>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="24" class="mb20" v-if="stateData.vmModel.Entity.OriginalDepartmentPosition">
							<el-form-item ref="Entity_OriginalDepartmentPosition_FormItem" prop="Entity.OriginalDepartmentPosition">
								<template #label>
									<WtmLabelTooltip label="原部门岗位" tooltip="手动输入原部门与岗位" />
								</template>
								<el-input v-model="stateData.vmModel.Entity.OriginalDepartmentPosition" disabled clearable></el-input>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_OriginalRank_FormItem" prop="Entity.OriginalRank">
								<template #label>
									<WtmLabelTooltip label="原职级" tooltip="原职级" />
								</template>
								<el-input v-model="stateData.vmModel.Entity.OriginalRank" disabled clearable class="width100"></el-input>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_OriginalBaseSalary_FormItem" prop="Entity.OriginalBaseSalary">
								<template #label>
									<WtmLabelTooltip label="原基本薪资" tooltip="原基本薪资" />
								</template>
								<el-input-number v-model="stateData.vmModel.Entity.OriginalBaseSalary" disabled clearable class="width100"></el-input-number>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_OriginalPositionSalary_FormItem" prop="Entity.OriginalPositionSalary">
								<template #label>
									<WtmLabelTooltip label="原岗位薪资" tooltip="原岗位薪资" />
								</template>
								<el-input-number v-model="stateData.vmModel.Entity.OriginalPositionSalary" disabled clearable class="width100"></el-input-number>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_OriginalPerformanceSalary_FormItem" prop="Entity.OriginalPerformanceSalary">
								<template #label>
									<WtmLabelTooltip label="原绩效薪资" tooltip="原绩效薪资" />
								</template>
								<el-input-number v-model="stateData.vmModel.Entity.OriginalPerformanceSalary" disabled clearable class="width100"></el-input-number>
							</el-form-item>
						</el-col>
					</el-row>
				</div>

				<div class="form-section">
					<div class="section-title">
						<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
						<span>调整后信息</span>
					</div>

					<el-row :gutter="20">
						<el-col :xs="24" :lg="12" class="mb20" v-if="!stateData.vmModel.Entity.NewDepartmentPosition">
							<WtmDeptSelector
								v-model:model-value="stateData.vmModel.Entity.NewGroupId"
								prop="Entity.NewGroupId"
								label="新部门"
								:auth="false"
								:rules="[]"
								:disabled="true"
							/>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20" v-if="!stateData.vmModel.Entity.NewDepartmentPosition">
							<el-form-item ref="Entity_NewPositionId_FormItem" prop="Entity.NewPositionId">
								<template #label>
									<WtmLabelTooltip label="新岗位" tooltip="新岗位" />
								</template>
								<el-select v-model="stateData.vmModel.Entity.NewPositionId" disabled clearable class="width100">
									<el-option v-for="item in stateData.AllSysJobPositions" :key="item.Value" :value="item.Value" :label="item.Text"></el-option
								></el-select>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="24" class="mb20" v-if="stateData.vmModel.Entity.NewDepartmentPosition">
							<el-form-item ref="Entity_NewDepartmentPosition_FormItem" prop="Entity.NewDepartmentPosition">
								<template #label>
									<WtmLabelTooltip label="新部门岗位" tooltip="手动输入新部门与岗位" />
								</template>
								<el-input v-model="stateData.vmModel.Entity.NewDepartmentPosition" disabled clearable></el-input>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_NewRank_FormItem" prop="Entity.NewRank">
								<template #label>
									<WtmLabelTooltip label="新职级" tooltip="新职级" />
								</template>
								<el-input v-model="stateData.vmModel.Entity.NewRank" disabled clearable class="width100"></el-input>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_NewBaseSalary_FormItem" prop="Entity.NewBaseSalary">
								<template #label>
									<WtmLabelTooltip label="新基本薪资" tooltip="新基本薪资" />
								</template>
								<el-input-number v-model="stateData.vmModel.Entity.NewBaseSalary" disabled clearable class="width100"></el-input-number>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_NewPositionSalary_FormItem" prop="Entity.NewPositionSalary">
								<template #label>
									<WtmLabelTooltip label="新岗位薪资" tooltip="新岗位薪资" />
								</template>
								<el-input-number v-model="stateData.vmModel.Entity.NewPositionSalary" disabled clearable class="width100"></el-input-number>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_NewPerformanceSalary_FormItem" prop="Entity.NewPerformanceSalary">
								<template #label>
									<WtmLabelTooltip label="新绩效薪资" tooltip="新绩效薪资" />
								</template>
								<el-input-number v-model="stateData.vmModel.Entity.NewPerformanceSalary" disabled clearable class="width100"></el-input-number>
							</el-form-item>
						</el-col>
					</el-row>
				</div>

				<div class="form-section">
					<div class="section-title">
						<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
						<span>履历信息</span>
					</div>

					<el-row :gutter="20">
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_TransferReason_FormItem" prop="Entity.TransferReason">
								<template #label>
									<WtmLabelTooltip label="调整原因" tooltip="调整原因" />
								</template>
								<el-input v-model="stateData.vmModel.Entity.TransferReason" disabled clearable class="width100"></el-input>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_Remark_FormItem" prop="Entity.Remark">
								<template #label>
									<WtmLabelTooltip label="备注" tooltip="履历备注" />
								</template>
								<el-input v-model="stateData.vmModel.Entity.Remark" disabled clearable class="width100"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
				</div>
			</el-form>
		</el-card>
	</div>
</template>

<script setup lang="ts" name="message._system.common.vm.edit;false">
import { reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { SysPersonResumeApi as api } from '/@/views/person/syspersonresume/api';
import other from '/@/utils/other';
import { ISysPersonResumeVm } from '/@/views/person/syspersonresume/api/interface';
import { IViewModel } from '/@/types/common';

const ci = getCurrentInstance() as any;
const loading = ref(false);
// 定义变量内容
const formRef = ref();
const stateData = reactive<IViewModel<ISysPersonResumeVm>>({
	vmModel: {
		Entity: {
			ID: null,
			PersonId: null,
			TransferRequestId: null,
			ResumeType: null,
			StartDate: null,
			EndDate: null,
			OriginalGroupId: null,
			OriginalPositionId: null,
			OriginalDepartmentPosition: null,
			OriginalRank: null,
			OriginalBaseSalary: null,
			OriginalPositionSalary: null,
			OriginalPerformanceSalary: null,
			NewGroupId: null,
			NewPositionId: null,
			NewDepartmentPosition: null,
			NewRank: null,
			NewBaseSalary: null,
			NewPositionSalary: null,
			NewPerformanceSalary: null,
			TransferReason: null,
			Remark: null,
		},
	},

	AllSysPersons: [] as any[],
	AllSysHrTransferRequestBills: [] as any[],
	AllSysJobPositions: [] as any[],
});

// 取消
const onClose = () => {
	closeDialog();
};

// 页面加载时
onMounted(() => {
	loading.value = true;
	if (ci.attrs['wtmdata']) {
		stateData.vmModel.Entity.ID = ci.attrs['wtmdata'].ID;
	}
	const promises: Promise<any>[] = [
		other.getSelectList('/api/SysPersonResume/GetSysHrTransferRequestBills', [], false).then((x) => {
			stateData.AllSysHrTransferRequestBills = x;
		}),

		other.getSelectList('/api/SysPersonResume/GetSysJobPositions', [], false).then((x) => {
			stateData.AllSysJobPositions = x;
		}),

		api()
			.get(stateData.vmModel.Entity.ID ?? '')
			.then((data: any) => other.setValue(stateData.vmModel, data)),
	];
	Promise.allSettled(promises).finally(() => {
		loading.value = false;
		nextTick(() => {
			setupHeaderButtons();
		});
	});
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh', 'closeDialog', 'updateHeaderButtons']);
// 关闭弹窗
const closeDialog = () => {
	emit('closeDialog');
};

// 设置对话框头部按钮
const setupHeaderButtons = () => {
	const headerButtons = [
		{
			text: ci.proxy.$t('message._system.common.vm.cancel'),
			type: 'default',
			onClick: onClose,
			visible: true,
		},
	];

	emit('updateHeaderButtons', headerButtons);
};
</script>

<style scoped>
.section-title {
	display: flex;
	align-items: center;
}
.title-spacer {
	flex: 1;
}
</style>
